﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
 
using BOHVote.BLL;
using BOHVote.Entity;

namespace BOH.ControlPanel
{
    public partial class ModifyUserInfo : System.Web.UI.Page
    {
        protected string ID = string.Empty;
        protected BHUser user = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                user = (BHUser)Session["User"];
                ID = user.UserID;
                fillForm(user);
            }
        }


        protected void fillForm(BHUser bu)
        {
            this.lblUserName.Text = bu.UserName;
            //this.txtPasswordOld.Text = bu.password;
            this.txtPasswordOld_H.Value = bu.password;
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            string PasswordNew_H = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPasswordNew_H.Value.Trim(), "MD5");
            string PasswordNewConfirm_H = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPasswordNewConfirm_H.Value.Trim(), "MD5");
            string PasswordOld_H = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPasswordOld.Text.Trim(), "MD5");
            if (PasswordNew_H == PasswordNewConfirm_H && PasswordOld_H == user.password)
            {
                UserClass.ModifyPassword(ID, PasswordNewConfirm_H);
            }
        }
    }
}
